package org.example.service.impl;

import org.example.mapper.EmployeeMapper;
import org.example.pojo.Employee;
import org.example.service.EmployeeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

@Service
public class EmployeeServiceImpl implements EmployeeService {
    @Autowired
    EmployeeMapper employeeMapper;

    /**
     * 多表连接查询全部员工并做分页显示
     * @return
     */
    @Override
    public List<Employee> showEmployees() {
        return employeeMapper.selectEmployees();
    }

    /**
     * 批量删除员工
     * @param ids
     * @return
     */
    @Override
    public int deleteEmployees(String[] ids) {
        return employeeMapper.deleteEmployees(ids);
    }

    /**
     * 单个删除员工
     * @param eId
     * @return
     */
    @Override
    public int deleteEmployee(int eId) {
        return employeeMapper.deleteEmployee(eId);
    }

    /**
     * 添加员工
     * @param employee
     * @return
     */
    @Override
    public int addEmployee(Employee employee) {
        return employeeMapper.addEmployee(employee);
    }

    /**
     * 修改员工
     * @param employee
     * @return
     */
    @Override
    public int updateEmployee(Employee employee) {
        return employeeMapper.updateEmployee(employee);
    }

    /**
     * 根据员工id查询员工
     * @param eId
     * @return
     */
    @Override
    public Employee showEmployeeById(int eId) {
        return employeeMapper.selectEmployeeById(eId);
    }

    /**
     * 多表连接模糊查询员工并做分页显示
     * @param message
     * @return
     */
    @Override
    public List<Employee> showEmployeesByAll(String message) {
        return employeeMapper.selectEmployeesByAll(message);
    }

    /**
     * 查询在职员工
     * @param msg
     * @return
     */
    @Override
    public List<Employee> showZaiZhiEmployees(String msg) {
        return employeeMapper.selectZaiZhiEmployees(msg);
    }

    /**
     * 模糊查询在职员工
     * @param map
     * @return
     */
    @Override
    public List<Employee> showZaiZhiEmployeesByAll(Map<String,String> map) {
        return employeeMapper.selectZaiZhiEmployeesByAll(map);
    }

    @Override
    public List<Employee> showLiZhiEmployeeByAll(Map<String, String> map) {
        return employeeMapper.selectLiZhiEmployeeByAll(map);
    }

    @Override
    public List<Employee> selectAllEmployees() {
        return employeeMapper.selectAllEmployees();

    }
    @Override
    public int insertTest(List<Employee> tests) {
        int insert = 0;
        for (Employee test : tests){
            insert += employeeMapper.addEmployee(test);
        }
        return insert;
    }

}
